<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/laydate/laydate.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
    <script type="text/javascript" src="../../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>

<table class="table-top">
		<tr>
			<td>
				<label class="label" id="otherin_add_tips"></label>
			</td>
			<td>
				<input type="text" n="date" class="input search-date" name="dateStart" autocomplete="off"/>&nbsp;-&nbsp;
				<input type="text" n="date" class="input search-date" name="dateEnd" autocomplete="off"/>
			</td>
			<td>
				<button class="button" id="query"><span>查询</span></button>
                <button class="button" id="create"><span>新增</span></button>
			</td>
		</tr>
	</table>
<div id="table"></div>

<script>
	var params = app.getRequestParams();
    $(function(){
        $('#create').click(function(){
            location.href = 'otherin_add.html'+'?type='+params.type;
        });

        $('#query').click(function(){
            var queryParams = app.serializeForm();
            queryParams.otherType = params.type;
            $("#table").datagrid("reload",queryParams);
        });

        var nowDate = app.time2str(new Date()),startDate = new Date(nowDate.substr(0,8)+'01');
        
        var dateStart = laydate.render({
            elem: 'input[name="dateStart"]',value:nowDate.substr(0,8)+'01',max:nowDate,
            done: function(value,date){
                if(value){
                    date.month=date.month-1;
                    dateEnd.config.min = date;
                }else{
                    dateEnd.config.min=dateStart.config.min;
                }
            }
        });
        var dateEnd = laydate.render({
            elem: 'input[name="dateEnd"]',value:nowDate,min:nowDate.substr(0,8)+'01',
            done: function(value,date){
                if(value){
                    date.month=date.month-1;
                    dateStart.config.max = date;
                }else{
                    dateStart.config.max=dateEnd.config.max;
                }
            }
        });

        var txt = params.type == 1?'入':'出';
        $('#otherin_add_tips').html(txt+'库日期');

        $('#table').datagrid({
            url:app.BASE_API_URL+'stoneOther/page',
            queryParams:{dateStart:startDate.getTime(),dateEnd:new Date().getTime(),otherType:params.type},
            columns:[
                {field:'date',title:txt+'库日期',width:100,formatter:app.timeFormatter},
                {field:'code',title:txt+'库编号',width:180,formatter:function (row) {
                    if( params.type == 1 ){
                        return '<a dg="1" data-id="'+row.id+'" class="a">QRC'+row.code+"</a>";
					}else{
                        return '<a dg="1" data-id="'+row.id+'" class="a">QCC'+row.code+"</a>";
					}
				}},
                {field:'number',title:txt+'库数量',width:100,formatter:function (row) {
						return app.div(row.number,100).replace('.00','');
                    }},
                {field:'remarks',title:'备注',width:100},
				{field:'userName',title:'制单人',width:100},
                {field:'status',title:'单据状态',width:100,formatter:function (row) {
					if( row.status == '1' ){
						return '<span class="label-status label-warning">未'+txt+'库</span>';
					}else if( row.status == '2' ){
						return '<span class="label-status label-success">已'+txt+'库</span>';
					}else if( row.status == '0' ){
						return '<span class="label-status label-warning">已作废</span>';
					}else{
						return '状态异常';
					}
				}}
            ],
            loadSuccess:loadDataSuccess
        });
    });

    function loadDataSuccess(){
        $('.a[dg="1"]').click(function(){
            var row = $(this).parent().parent().data();
            location.href = "otherin_add.html?code="+row.code+"&id="+row.id+"&status="+row.status+"&type="+params.type;
        });
    }
</script>

</body>
</html>